package com.incar.chuxing.payAndShare;

import android.app.Activity;
import android.content.Context;

import com.incar.chuxing.utils.ToastUtils;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * Created by michaelpi on 2018/6/11.
 */

public class WxLoginUtil {
    private Context mContext;

    public WxLoginUtil(Context mContext) {
        this.mContext = mContext;
    }

    public boolean wxLogin(String appId, String scope, String state) {
        final IWXAPI wxapi = WXAPIFactory.createWXAPI(mContext, null);
        wxapi.registerApp(appId);
        if (!wxapi.isWXAppInstalled()) {
            ((Activity) mContext).runOnUiThread(() -> ToastUtils.makeText(mContext, "请您先安装微信", ToastUtils.LENGTH_SHORT).show());
            return false;
        }
        final SendAuth.Req req = new SendAuth.Req();
        req.scope = scope;
        req.state = state;
        wxapi.sendReq(req);
        return true;
    }


}
